package cn.edu.javaweb.userServlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.javaweb.utils.DBUtil;

@WebServlet("/ForumResponseDeleteServlet")
public class ForumResponseDeleteServlet extends HttpServlet {
	DBUtil db;
	private static final long serialVersionUID = 1L;
    
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id=request.getParameter("id");
		String qid=request.getParameter("qid");
		
		System.out.println(id);
		db = new DBUtil();  //new的时候在调用（工具类）构造函数（初始化），实现数据库的搭建
		String SQL = "delete from response where id='"+id+"'";
		System.out.print(SQL);
		int result=db.update(SQL);  //调用（工具类）update方法，result来传递结果
		response.setContentType("text/html;charset=utf-8");
	    PrintWriter out=response.getWriter();
	    if(result>0){
	    	//response.sendRedirect("/ForumResponseServlet?id="+qid+"");
	    	//response.sendRedirect(request.getContextPath()+"/ForumResponseServlet?id="+qid+"");
	    	out.println("<script language=javascript>alert('删除成功');window.location='ForumResponseServlet?id="+qid+"';</script>");
	    }else{
	    	out.println("<script language=javascript>alert('删除失败,请重新删除');window.location='ForumResponseServlet?id="+qid+"';</script>");
		}
	}

}
